# https://www.kimi.com/chat/d21cto5s8fb5gej8tukg
import numpy as np
from sklearn.svm import SVC
import matplotlib.pyplot as plt

X = np.array([[2.1],[2.3],[2.4],[2.6],[2.8]])
y = np.array([0,0,0,1,1])          # 0=香蕉, 1=西瓜
xline = np.linspace(2.0, 3.0, 300).reshape(-1,1)

for C in [1000, 1, 0.01]:
    clf = SVC(kernel='linear', C=C)
    clf.fit(X, y)
    pred = clf.decision_function(xline)
    plt.plot(xline, pred, label=f'C={C}')
    plt.axhline(0, color='gray', ls='--')
    plt.scatter(X, [0]*len(X), c=y, cmap='coolwarm')
plt.legend(); plt.xlabel('重量'); plt.ylabel('决策函数值'); plt.show()